package com.jk.mapper;


import com.jk.model.*;
import org.apache.ibatis.annotations.*;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

@Mapper
public interface ZSLMapper {
    /**
     * 查询权限树
     * @param id
     * @return
     */
    @Select("select * from t_manage where  pid = #{value}")
    List<ManageBean> findManage(int id);

    /**
     * 查询用户总条数
     * @param param
     * @return
     */
    int findUserCount(HashMap<String, Object> param);

    /**
     * 查询用户信息
     * @param param
     * @return
     */
    List<UserBean> findUserList(HashMap<String, Object> param);

    void delUserById(Integer[] ids);

    int findUserShopCount(HashMap<String, Object> param);

    List<UserBean> findUserShopList(HashMap<String, Object> param);

    int shopTableCount(HashMap<String, Object> param);

    List<ProductBean> shopTableList(HashMap<String, Object> param);

    int findOrderCount(HashMap<String, Object> param);

    List<OrderBean> findOrderList(HashMap<String, Object> param);

    int findShopUserCount(HashMap<String, Object> param);

    List<UserBean> findShopUserList(HashMap<String, Object> param);

    int orderTableCount(HashMap<String, Object> param);

    List<OrderBean> orderTableList(HashMap<String, Object> param);

    @Select("select tp.*,ts.stockNumber from t_product tp " +
            "   left join t_stock ts on tp.productStockId=ts.id" +
            " where tp.id = #{value}")
    ProductBean queryProductByProductId(Integer productId);

    @Select("select * from t_user_acceptsite where userId = #{value};")
    List<AcceptsiteBean> chaAddress(int i);

    @Select("select * from t_product where id = #{value};")
    OrderBean chajiaoyi(Integer productId);

    @Delete("delete from t_user_acceptsite where id = #{value}")
    void deleteaddress(Integer id);

    @Insert("insert into t_user_acceptsite (acceptName, acceptPhone, acceptSite, userId, acceptProvince, acceptCity, acceptArea)   " +
            "values (#{acceptName},#{acceptPhone},#{acceptSite},#{userId},#{acceptProvince},#{acceptCity},#{acceptArea})")
    void addressdizhi(AcceptsiteBean acceptsiteBean);

    @Update("update t_user_acceptsite set acceptName=#{acceptName},acceptPhone=#{acceptPhone},acceptSite=#{acceptSite},acceptProvince=#{acceptProvince}," +
            "acceptCity=#{acceptCity},acceptArea=#{acceptArea} where id=#{id}")
    void addressdizhiUpdate(AcceptsiteBean acceptsiteBean);

    void adddingdan(ArrayList<OrderBean> orderBeanArrayList);

    @Update("update t_order tod set tod.orderStatus = 2, tod.acceptstiseId=#{id} where tod.orderNo =#{orderBeanArrayList}")
    void updateOrder(@RequestParam("orderBeanArrayList") String orderBeanArrayList, @RequestParam("id") Integer id);

    @Update("update t_stock ts,t_product_stock tps set ts.stockNumber=stockNumber-#{count} where tps.stockId=ts.id and tps.productId=#{productId}")
    void updateNumber(@RequestParam("productId") Integer productId,@RequestParam("count") Integer count);

    @Select("select * from t_order where orderStatus=1")
    List<OrderBean> findOrderByStart();

    @Update("update t_order set orderStatus = 3 where id=#{value}")
    void updateOrderById(Integer id);

    @Update("update t_stock ts,t_product_stock tps set ts.stockNumber=stockNumber+#{productCount} where tps.stockId=ts.id and tps.productId=#{productId}")
    void updateNumberByOrder(@RequestParam("productId") Integer productId,  @RequestParam("productCount")Integer productCount);

    int queryOrderCount(HashMap<String, Object> param);

    List<OrderBean> queryOrderList(HashMap<String, Object> param);
}
